package triggerhelper.errorChecks.possibleErrors;

import java.awt.Component;
import javax.swing.JOptionPane;
import triggerhelper.errorChecks.PossibleError;

public class MinMax implements PossibleError{

    private int min, max;

    public MinMax(int min_, int max_){
        min = min_;
        max = max_;
    }

    public boolean check(String input_, String name, Component parent) {
        boolean valid = true;
        int input = 0;
        try{
            input = Integer.parseInt(input_);
        }catch(NumberFormatException e){
            JOptionPane.showMessageDialog(parent, "I'm sorry, the " + name + " does not seem to be a valid number.");
            valid = false;
        }
        if(valid){
            if(input < min){
                JOptionPane.showMessageDialog(parent, "I'm sorry, the " + name + " needs to be higher than " + min + ".");
                valid = false;
            }else if(input > max){
                JOptionPane.showMessageDialog(parent, "I'm sorry, the " + name + " needs to be less than " + max + ".");
                valid = false;
            }
        }
        return valid;
    }



}
